<html>

<head>
<title>SQL Relay - Getting Started With IBM DB2</title>
<link rel="stylesheet" href="../css/styles.css">
</head>

<body>

<span class="heading1">Getting Started With IBM DB2</span><br>

<ul>
<li><a href="#installation">Installation</a></li>
<ul>
<li><a href="#pdksh">Install pdksh</a></li>
<li><a href="#rpm">Install RPM</a></li>
<li><a href="#env">PATH Environment Variable</a></li>
<li><a href="#db2">DB2 Installation</a></li>
</ul>
<li><a href="#creating">Creating a Database</a></li>
<li><a href="#accessing">Accessing a Database</a></li>
<ul>
<li><a href="#accessinglocal">Accessing a Local Database</a></li>
<li><a href="#accessingremote">Accessing a Remote Database</a></li>
<li><a href="#usingdb2">Using the DB2 Client Program</a></li>
<li><a href="#usingdb2icc">Using the DB2 Information and Control Centers</a></li>
</ul>
<li><a href="#sqlrelay">Accessing a Database With SQL Relay</a></li>
<li><a href="#caveat">Caveat</a></li>
</ul>

<a name="installation"></a>
<span class="heading1">Installation</span><br>

<p>I've sucessfully installed DB2 Enterprise Edition versions 7.2 and 8.1 on
Linux, DB2 Personal Edition version 8.2 on Linux and DB2 Express Editions 8.2.4
and 9.1 on Linux.  I've never had access to any other version of DB2 for Linux
or any version of DB2 for other platforms.</p>

<a name="rpm"></a>
<span class="heading2">Install RPM</span><br>

<p>When installing versions of DB2 below 9.1, on non-RPM based systems, you'll
need to install RPM.</p>

<p>For Slackware Linux, the RPM package is available from 
<a href="ftp://ftp.slackware.com">ftp.slackware.com</a>.  You can install it 
using <i>installpkg</i>.  Once RPM is installed, log in as root and run
<i>rpm --initdb</i>.</p>

<p>On newer Debian releases, if you have configured <i>apt</i> as illustrated 
in <a href="http://www.debian.org/doc/manuals/apt-howto/index.en.html">the 
APT-HOWTO</a>, run <i>apt-get install rpm</i>.  If your distribution came with
RPM, you may be prompted to enter a CD.  If not, it will be downloaded from the
internet.  Once RPM is installed, log in as root and run <i>rpm --initdb</i>.

<p>On systems where the <i>rpm</i> command resides in /usr/bin,  you need to 
create a symbolic link between <i>/usr/bin/rpm</i> and <i>/bin/rpm</i> as 
follows.</p>

<blockquote>
<b>ln -s /usr/bin/rpm /bin/rpm</b>
</blockquote>

<a name="env"></a>
<span class="heading2">PATH Environment Variable</span><br>

<p>For versions 7.2, 8.1 and 8.2 (though apparently not for versions above 8.2),
the DB2 installer tries to run some command line programs that are found in 
sbin and /usr/sbin.  Make sure that these directories are in the root user's
PATH.</p>

<a name="db2"></a>
<span class="heading2">DB2 Installation</span><br>

<p>Each version of DB2 has a slightly different installation procedure.
Follow the links below for the version of DB2 that you are installing.</p>

<p><a href="db2/72.html">Installing IBM DB2 Enterprise V7.2</a><br>
<a href="db2/81.html">Installing IBM DB2 Enterprise V8.1</a><br>
<a href="db2/82.html">Installing IBM DB2 Personal V8.2</a></p>
<a href="db2/824.html">Installing IBM DB2 Express V8.2.4</a></p>
<a href="db2/91.html">Installing IBM DB2 Express V9.1</a></p>

<a name="creating"></a>
<span class="heading2">Creating a Database</span><br>

<p>Now that you have created an instance, you must create a database within
the instance.  Log in as db2inst1 and run the following command to create a
database named <i>testdb</i>.</p>

<blockquote>
<b>db2 "create database testdb"</b>
</blockquote>

<p>Should you need to drop a database, the following command drops a database
named <i>testdb</i>.</p>

<blockquote>
<b>db2 "drop database testdb"</b>
</blockquote>

<a name="accessing"></a>
<span class="heading1">Accessing a Database</span><br>

<br><br>

<a name="accessinglocal"></a>
<span class="heading2">Accessing a Local Database</span><br>

<p>Accessing a local DB2 database using the db2 client tool is simple.  For 
example, to access a database called <i>testdb</i> in the <i>db2inst1</i> 
instance, owned by the <i>db2inst1</i> user on the local machine, log in as 
<i>db2inst1</i> and run the <i>db2</i> command.  Then use the CONNECT
command to connect to a particular database.</p>

<blockquote>
<PRE>
[db2inst1@localhost db2inst1]$ <b>db2</b>
c(c) Copyright IBM Corporation <FONT color=#ff00ff>1993</FONT>,<FONT color=#ff00ff>2001</FONT>
Command Line Processor for DB2 SDK <FONT color=#ff00ff>7.2</FONT>.<FONT color=#ff00ff>0</FONT>

You can issue database manager commands and SQL statements from the command 
prompt. For example:
    db2 =&gt; <FONT color=#6959cf>connect</FONT> <FONT color=#6959cf>to</FONT> sample
    db2 =&gt; bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside 
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

<b>db2 =&gt; <FONT color=#6959cf>connect</FONT> <FONT color=#6959cf>to</FONT> testdb</b>

   Database Connection Information

 Database server        = DB2/LINUX <FONT color=#ff00ff>7.2</FONT>.<FONT color=#ff00ff>0</FONT>
 SQL authorization ID   = DB2INST1
 Local database alias   = TESTDB

</PRE>
</blockquote>

<a name="accessingremote"></a>
<span class="heading2">Accessing a Remote Database</span><br>

<p>If you want to access a database on a remote machine, the process is more
complex.  DB2 or "DB2 Connect" must be installed on the local and remote 
machines and a DB2 or "DB2 Connect" instance must be created on the local 
machine.  "DB2 Connect" is a lightweight version of the DB2 database system
whose instances cannot support a local database, and can only provide 
connectivity to a remote instance.  In the instance on the local machine, use 
the CATALOG command to create aliases for the remote instance and 
database.  Once these aliases are created, you can use the database alias to
connect to the remote database.</p>

<p>Take the following scenario:</p>

<blockquote>
<table border="1">
<tr><td colspan="2"><b>local machine</b></td></tr>
<tr><td>Hostname</td><td><i>localhost</i></td></tr>
<tr><td>Instance</td><td><i>db2inst1</i></td></tr>
</table>
</blockquote>

<blockquote>
<table border="1">
<tr><td colspan="2"><b>remote machine</b></td></tr>
<tr><td>Hostname</td><td><i>remotehost</i></td></tr>
<tr><td>Instance</td><td><i>testinst<br>
<pre>
	owned by user testinst with password testpassword
	allows remote connections on port 50000
<pre>
</i></td></tr>
<tr><td>Database</td><td><i>testdb</i></td></tr>
</table>
</blockquote>

<p>On <i>localhost</i>, in the <i>db2inst1</i> instance, to create an instance
alias named <i>remoteinst</i> referring to <i>testinst</i> on 
<i>remotehost</i>, and a database alias named <i>remotedb</i> referring to 
<i>testdb</i>, follow this procedure.</p>

<blockquote>
log in as db2inst1 on localhost<br>
create the instance alias using the following commands:<br>
<blockquote><b>
db2 "catalog tcpip node <i>remoteinst</i> remote <i>remotehost</i> server
<i>50000</i>"<br>
db2 "terminate"<br>
</b></blockquote>
create the database alias using the following commands:<br>
<blockquote><b>
db2 "catalog database <i>testdb</i> as <i>remotedb</i> at node 
<i>remoteinst</i> authentication server"<br>
db2 "terminate"<br>
</b></blockquote>
</blockquote>

<p>Now that the aliases have been created, you can connect to the database alias
using the CONNECT comamnd.  Note that you must supply the user name and 
password.</p>

<blockquote>
<PRE>
[db2inst1@localhost db2inst1]$ <b>db2</b>
c(c) Copyright IBM Corporation <FONT color=#ff00ff>1993</FONT>,<FONT color=#ff00ff>2001</FONT>
Command Line Processor for DB2 SDK <FONT color=#ff00ff>7.2</FONT>.<FONT color=#ff00ff>0</FONT>

You can issue database manager commands and SQL statements from the command 
prompt. For example:
    db2 =&gt; <FONT color=#6959cf>connect</FONT> <FONT color=#6959cf>to</FONT> sample
    db2 =&gt; bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside 
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

<b>db2 =&gt; <FONT color=#6959cf>connect</FONT> <FONT color=#6959cf>to</FONT> remotedb <FONT color=#6959cf>user</FONT> testinst <FONT color=#6959cf>using</FONT> testpassword</b>

   Database Connection Information

 Database server        = DB2/LINUX <FONT color=#ff00ff>7.2</FONT>.<FONT color=#ff00ff>0</FONT>
 SQL authorization ID   = TESTINST
 Local database alias   = REMOTEDB

</PRE>
</blockquote>

<p>If you need to get a list of instance aliases, you can use the LIST NODE 
DIRECTORY command as follows.</p>

<blockquote>
<b>db2 "list node directory"</b>
</blockquote>

<p>To list the database aliases, you can use the LIST DATABASE DIRECTORY
command.  Note that this command lists local databases as well as remote
databases.</p>

<blockquote>
<b>db2 "list database directory"</b>
</blockquote>

<p>If you need to drop a database or instance alias, use the UNCATALOG command.
The following commands remove the <i>remotedb</i> database alias and the
<i>remoteinst</i> instance alias.</p>

<blockquote><b>
db2 "uncatalog database <i>remotedb</i>"<br>
db2 "uncatalog node <i>remoteinst</i>"<br>
db2 "terminate"
</b></blockquote>

<a name="usingdb2"></a>
<span class="heading1">Using the DB2 Client Program</span><br>

<p>When run with no arguments, the <i>db2</i> client program provides an 
interactive shell, prompting you to enter commands or an SQL queries.  Commands 
or queries must be entered on a single line and will run when the Enter or 
Return key is pressed.  To exit, type quit.</p>

<p>A sample <i>db2</i> session follows.</p>

<blockquote>
<PRE>
[db2inst1@localhost db2inst1]$ <b>db2</b>
c(c) Copyright IBM Corporation <FONT color=#ff00ff>1993</FONT>,<FONT color=#ff00ff>2001</FONT>
Command Line Processor for DB2 SDK <FONT color=#ff00ff>7.2</FONT>.<FONT color=#ff00ff>0</FONT>

You can issue database manager commands and SQL statements from the command 
prompt. For example:
    db2 =&gt; <FONT color=#6959cf>connect</FONT> <FONT color=#6959cf>to</FONT> sample
    db2 =&gt; bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside 
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

<b>db2 =&gt;</b> <FONT color=#6959cf>connect</FONT> <FONT color=#6959cf>to</FONT> testdb

   Database Connection Information

 Database server        = DB2/LINUX <FONT color=#ff00ff>7.2</FONT>.<FONT color=#ff00ff>0</FONT>
 SQL authorization ID   = DB2INST1
 Local database alias   = TESTDB

<b>db2 =&gt;</b> <B><FONT color=#a62828>create</FONT></B> <FONT color=#6959cf>table</FONT> testtable (col1 <B><FONT color=#288a51>char</FONT></B>(<FONT color=#ff00ff>40</FONT>), col2 int)
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> list tables

Table/View                      Schema          Type  Creation time
<FONT color=#0000ff>------------------------------- --------------- ----- --------------------------</FONT>
TESTTABLE                       DB2INST1        T     <FONT color=#ff00ff>2002-03-01-01</FONT>.<FONT color=#ff00ff>55</FONT>.<FONT color=#ff00ff>19</FONT>.<FONT color=#ff00ff>671629</FONT>

  <FONT color=#ff00ff>1</FONT> record(s) selected.

<b>db2 =&gt;</b> describe <FONT color=#6959cf>table</FONT> testtable show detail

Column                         Type                                                                                        Column     Partitioning key    Code
name                           schema                          Type name                       Length    Scale    Nulls    number     sequence            page     Default
<FONT color=#0000ff>------------------------------ ------------------------------- ------------------------------- --------- -------- -------- ---------- ------------------- -------- ----------------------------------------</FONT>
COL1                           SYSIBM                          <B><FONT color=#288a51>CHARACTER</FONT></B>                              <FONT color=#ff00ff>40</FONT>        <FONT color=#ff00ff>0</FONT> Yes               <FONT color=#ff00ff>0</FONT>                   <FONT color=#ff00ff>0</FONT>      <FONT color=#ff00ff>819</FONT>                                                                                                                                                                                                                                                               
COL2                           SYSIBM                          <B><FONT color=#288a51>INTEGER</FONT></B>                                 <FONT color=#ff00ff>4</FONT>        <FONT color=#ff00ff>0</FONT> Yes               <FONT color=#ff00ff>1</FONT>                   <FONT color=#ff00ff>0</FONT>        <FONT color=#ff00ff>0</FONT>                                                                                                                                                                                                                                                               

  <FONT color=#ff00ff>2</FONT> record(s) selected.

<b>db2 =&gt;</b> <B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> testtable <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'hello'</FONT>,<FONT color=#ff00ff>50</FONT>)
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> <B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> testtable <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'hi'</FONT>,<FONT color=#ff00ff>60</FONT>)
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> <B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> testtable <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'bye'</FONT>,<FONT color=#ff00ff>70</FONT>)
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> <B><FONT color=#a62828>select</FONT></B> * <FONT color=#6959cf>from</FONT> testtable

COL1                                     COL2       
<FONT color=#0000ff>---------------------------------------- -----------</FONT>
hello                                             <FONT color=#ff00ff>50</FONT>
hi                                                <FONT color=#ff00ff>60</FONT>
bye                                               <FONT color=#ff00ff>70</FONT>

  <FONT color=#ff00ff>3</FONT> record(s) selected.

<b>db2 =&gt;</b> <B><FONT color=#a62828>update</FONT></B> testtable <B><FONT color=#a62828>set</FONT></B> col2=<FONT color=#ff00ff>0</FONT> <FONT color=#6959cf>where</FONT> col1=<FONT color=#ff00ff>'hi'</FONT>
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> <B><FONT color=#a62828>select</FONT></B> * <FONT color=#6959cf>from</FONT> testtable

COL1                                     COL2       
<FONT color=#0000ff>---------------------------------------- -----------</FONT>
hello                                             <FONT color=#ff00ff>50</FONT>
hi                                                 <FONT color=#ff00ff>0</FONT>
bye                                               <FONT color=#ff00ff>70</FONT>

  <FONT color=#ff00ff>3</FONT> record(s) selected.

<b>db2 =&gt;</b> <B><FONT color=#a62828>delete</FONT></B> <FONT color=#6959cf>from</FONT> testtable <FONT color=#6959cf>where</FONT> col2=<FONT color=#ff00ff>50</FONT>
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> <B><FONT color=#a62828>select</FONT></B> * <FONT color=#6959cf>from</FONT> testtable

COL1                                     COL2       
<FONT color=#0000ff>---------------------------------------- -----------</FONT>
hi                                                 <FONT color=#ff00ff>0</FONT>
bye                                               <FONT color=#ff00ff>70</FONT>

  <FONT color=#ff00ff>2</FONT> record(s) selected.

<b>db2 =&gt;</b> <B><FONT color=#a62828>drop</FONT></B> <FONT color=#6959cf>table</FONT> testtable
DB20000I  The SQL command completed successfully.
<b>db2 =&gt;</b> quit
DB20000I  The QUIT command completed successfully.
</PRE>
</blockquote>

<a name="usingdb2icc"></a>
<span class="heading1">Using the DB2 Information and Control Centers</span><br>

<p>IBM DB2 comes with a set of user-friendly, Java-based GUI utilities for 
browsing and configuring database instances.</p>

<p>These utilities require the Java Runtime Enviroment version 1.1.8 
or higher.  For Linux, JRE's are available as RPM's or 
tarballs from <a href="http://www.blackdown.org">Blackdown</a>,
<a href="http://java.sun.com">Sun</a> and
<a href="http://www.ibm.com/java/jdk">IBM</a>.  Of course, IBM recommends that
you use their JRE.</p>

<p>To run the DB2 Information Center or Control Center, you have to log in as
a database instance or adminstrative server owner such as <i>db2as</i> or
<i>db2inst1</i>.</p>

<p>Make sure that the <i>jre</i> command is in the PATH environment variable 
for that user.  If it isn't, modify that user's .bashrc to include it.</p>

<p>If you are running a 2.4 (or higher) kernel, add the following line to the
user's .bashrc as well.</p>

<blockquote>
<b>export LD_ASSUME_KERNEL=2.2.5</b>
</blockquote>

<p>If you are running a kernel with Native Posix Threading Library support
(such as on Redhat 9) then you need to add this line instead:</p>

<blockquote>
<b>export LD_ASSUME_KERNEL=2.4.1</b>
</blockquote>

<p>This may be necessary on other systems too.  It is definitely necessary on
Redhat 9.</p>

<p>To run the Information Center or Control Center, you first have to run the
DB2 Java Server and give it a port number as follows.</p>

<blockquote>
<b>db2jstrt 6720</b>
</blockquote>

<p>Once it's running, you can run the DB2 Information Center or Control Center,
also supplying the port.</p>

<blockquote>
<b>db2ic 6720</b><br><br>
or<br><br>
<b>db2cc 6720</b>
</blockquote>

<p>Both utilities will ask for the username and password of an instance owner.  
Once you supply these credentials, you can browse and/or configure the instance 
owned by that user.</p>

<a name="sqlrelay"></a>
<span class="heading1">Accessing a Database With SQL Relay</span><br>

<p>Accessing DB2 from SQL Relay requires an instance entry in your 
<i>sqlrelay.conf</i> file for the database that you want 
to access.  Here is an example <i>sqlrelay.conf</i> which defines an SQL Relay 
instance called db2test.  This SQL Relay instance connects to the 
<i>testdb</i> database in the <i>db2inst1</i> DB2 instance.</p>

<p><b>Important Note:</b> For DB2 connections, <i>sqlr-start</i> must be run as
the user that owns the DB2 instance that it is running against.  In this 
example, the <i>db2inst1</i> user owns the <i>db2inst1</i> instance where the 
<i>testdb</i> database resides, so <i>sqlr-start</i> must be run as 
<i>db2inst1</i>.</p>

<PRE>
<FONT color=#0000ff>&lt;?</FONT><B><FONT color=#288a51>xml version=</FONT></B><FONT color=#ff00ff>&quot;1.0&quot;</FONT><FONT color=#0000ff>?&gt;</FONT>
<FONT color=#008a8e>&lt;!</FONT><B><FONT color=#a62828>DOCTYPE</FONT></B> instances <B><FONT color=#a62828>SYSTEM</FONT></B> <FONT color=#ff00ff>&quot;sqlrelay.dtd&quot;</FONT><FONT color=#008a8e>&gt;</FONT>
<FONT color=#008a8e>&lt;instances&gt;</FONT>

        <FONT color=#008a8e>&lt;instance id=</FONT><FONT color=#ff00ff>&quot;db2test&quot;</FONT><FONT color=#008a8e> port=</FONT><FONT color=#ff00ff>&quot;9000&quot;</FONT><FONT color=#008a8e> socket=</FONT><FONT color=#ff00ff>&quot;/tmp/db2test.socket&quot;</FONT><FONT color=#008a8e> dbase=</FONT><FONT color=#ff00ff>&quot;db2&quot;</FONT><FONT color=#008a8e> connections=</FONT><FONT color=#ff00ff>&quot;3&quot;</FONT><FONT color=#008a8e> maxconnections=</FONT><FONT color=#ff00ff>&quot;5&quot;</FONT><FONT color=#008a8e> maxqueuelength=</FONT><FONT color=#ff00ff>&quot;0&quot;</FONT><FONT color=#008a8e> growby=</FONT><FONT color=#ff00ff>&quot;1&quot;</FONT><FONT color=#008a8e> ttl=</FONT><FONT color=#ff00ff>&quot;60&quot;</FONT><FONT color=#008a8e> endofsession=</FONT><FONT color=#ff00ff>&quot;commit&quot;</FONT><FONT color=#008a8e> sessiontimeout=</FONT><FONT color=#ff00ff>&quot;600&quot;</FONT><FONT color=#008a8e> runasuser=</FONT><FONT color=#ff00ff>&quot;db2inst1&quot;</FONT><FONT color=#008a8e> runasgroup=</FONT><FONT color=#ff00ff>&quot;db2inst1&quot;</FONT><FONT color=#008a8e> cursors=</FONT><FONT color=#ff00ff>&quot;5&quot;</FONT><FONT color=#008a8e> authtier=</FONT><FONT color=#ff00ff>&quot;listener&quot;</FONT><FONT color=#008a8e> handoff=</FONT><FONT color=#ff00ff>&quot;pass&quot;</FONT><FONT color=#008a8e>&gt;</FONT>
                <FONT color=#008a8e>&lt;users&gt;</FONT>
                        <FONT color=#008a8e>&lt;user user=</FONT><FONT color=#ff00ff>&quot;testuser&quot;</FONT><FONT color=#008a8e> password=</FONT><FONT color=#ff00ff>&quot;testpassword&quot;</FONT><FONT color=#008a8e>/&gt;</FONT>
                <FONT color=#008a8e>&lt;/users&gt;</FONT>
                <FONT color=#008a8e>&lt;connections&gt;</FONT>
                        <FONT color=#008a8e>&lt;connection connectionid=</FONT><FONT color=#ff00ff>&quot;db2test&quot;</FONT><FONT color=#008a8e> string=</FONT><FONT color=#ff00ff>&quot;db=testdb&quot;</FONT><FONT color=#008a8e> metric=</FONT><FONT color=#ff00ff>&quot;1&quot;</FONT><FONT color=#008a8e>/&gt;</FONT>
                <FONT color=#008a8e>&lt;/connections&gt;</FONT>
        <FONT color=#008a8e>&lt;/instance&gt;</FONT>

<FONT color=#008a8e>&lt;/instances&gt;</FONT>
</PRE>

<p>Now you can start up this instance with the following command.</p>

<blockquote>
<b>su - db2inst1 -c "sqlr-start -id db2test"</b>
</blockquote>

<p>To connect to the instance and run queries, use the following command.</p>

<blockquote>
<b>sqlrsh -id db2test</b>
</blockquote>

<p>The following command shuts down the SQL Relay instance.</p>

<blockquote>
<b>su - db2inst1 -c "sqlr-stop db2test"</b>
</blockquote>

<a name="caveat"></a>
<span class="heading1">Caveat</span><br>

<p>For some reason, when SQL Relay connects to a DB2 database running on the
same machine as SQL Relay is running on, a problem occurs.  SQL Relay succeeds
in logging into the database, but upon running the first query, SQL Relay
receives the following error:

<blockquote><b>
-1224: [IBM][CLI Driver] SQL1224N  The database manager is not able to accept new requests, has terminated all requests in progress, or has terminated your particular request due to a problem with your request.  SQLSTATE=55032
</b></blockquote>

<p>SQL Relay is configured to re-login when it sees this error and afterward,
everything works well.  It's very strange, and prior to SQL Relay version 0.39,
SQL Relay got around this by having the sqlr-connection-db2 daemon detach from
the controlling tty afer logging into the database.  Somehow that avoided the
problem.  But adding the "reloginatstart" parameter made it necessary to detach
before logging into the database.</p>

<p>When connecting to a local database, the DB2 API uses System V IPC (shared
memory, semaphores and message queues) to talk to the database.  However, if
you use TCP to connect to the local database, the problem doesn't occur.</p>

<p>See <a href="#accessingremote">Accessing a Remote Database</a> above for
more detail, but to connect to a local database over TCP, you need to
execute the commands like the following as whatever user owns the local
database you want to connect to.  These commands enable you to connect to
a local database called <b>testdb</b> using the name <b>testdb1</b>.</p>

<blockquote>
<b>catalog tcpip node local remote localhost server 50000</b><br>
<b>terminate</b>
</blockquote>

<p>Then run:</p>

<blockquote>
<b>atalog database testdb as testdb1 at node local authentication server</b><br>
<b>terminate</b>
</blockquote>

<p>Now you can use the following SQL Relay connect string to connect to it:</p>

<blockquote>
db=testdb1;user=db2inst1;password=db2inst1
</blockquote>

</body>

</html>
